package com.txtsqlclient.domain;

import java.sql.Connection;

/**
 * @author spadda
 *
 */
public class FileDataSource extends DataSource {

	protected String fileName;

	protected String fileExtenion;

	protected boolean headerPresent;

	public FileDataSource(final DataSourceType dsType) {
		this.dsType = dsType;
	}

	public FileDataSource(final DataSourceType dsType, final String fileName,
			final String fileExtension, final boolean headerPresent) {
		this.dsType = dsType;
		this.fileName = fileName;
		this.fileExtenion = fileExtension;
		this.headerPresent = headerPresent;
	}

	protected void setDsType(final DataSourceType dsType) {
		if (DataSourceFactory.LEGAL_FILE_DATASOURCE_TYPES.contains(dsType)) {
			this.dsType = dsType;
		} else {
			throw new IllegalArgumentException("The given Data Source Type, :"
					+ dsType + " is not a valid File Data Source.");
		}
	}

	/* (non-Javadoc)
	 * @see com.txtsqlclient.domain.DataSource#openConnection()
	 */
	@Override
	public Connection openConnection() {
		throw new UnsupportedOperationException();
	}

	/* (non-Javadoc)
	 * @see com.txtsqlclient.domain.DataSource#readConnectionDetailsFromFile()
	 */
	@Override
	public void readConnectionDetailsFromFile() {
		throw new UnsupportedOperationException();

	}

	/* (non-Javadoc)
	 * @see com.txtsqlclient.domain.DataSource#writeConnectionDetailsToFile()
	 */
	@Override
	public void writeConnectionDetailsToFile() {
		throw new UnsupportedOperationException();

	}

	public String formatURL(String urlFormatStr) {
		throw new UnsupportedOperationException();
	}

	public int hashCode() {
		final int prime = 31;
		int hashCode = 7;
		hashCode = prime * hashCode + this.dsType.hashCode();
		hashCode = prime * hashCode + this.fileName.hashCode();
		return hashCode;
	}

	public boolean equals(final Object ds) {
		if (ds instanceof FileDataSource) {
			FileDataSource fds = (FileDataSource) ds;
			if (this.dsType.equals(fds.dsType)
					&& this.fileName.equals(fds.fileName)) {
				return true;
			}
		}
		return false;
	}
}
